package com.example.attendancesystem_1_8;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

//import android.support.v7.recyclerview.*;
//import android.support.v7.widget.RecyclerView;


public class Adapter extends RecyclerView.Adapter<Adapter.MyViewHolder>
{

    private static final String TAG = Adapter.class.getSimpleName();
    private List<String> mList = new ArrayList<>();
    private Context mContext;

    public Adapter(Context context)
    {
        mContext = context;
    }

    public void setVerticalDataList(List<String> list)
    {
        Log.d(TAG, "setVerticalDataList: " + list.size());
        mList = list;
        notifyDataSetChanged();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType)
    {
        View view = LayoutInflater.from(mContext).inflate(R.layout.tab01, viewGroup, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder myViewHolder, int j)
    {
        int m = j + 1;
        myViewHolder.tvNum.setText("这是第" + m + "条某讯新闻");
        myViewHolder.tvContent.setText(mList.get(j));
    }

    @Override
    public int getItemCount()
    {
        return mList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder
    {
        TextView tvNum, tvContent;
        public MyViewHolder(View itemView)
        {
            super(itemView);
        }
    }
}


